package com.hjm.project.bankRequestdata.bankRequestdata.controller;

import java.util.List;

import com.hjm.common.utils.Utils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.bankRequestdata.bankRequestdata.domain.BankRequestdata;
import com.hjm.project.bankRequestdata.bankRequestdata.service.IBankRequestdataService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 请求渠道Controller
 * 
 * @author LOVE
 * @date 2020-11-27
 */
@Controller
@RequestMapping("/bankRequestdata/bankRequestdata")
public class BankRequestdataController extends BaseController
{
    private String prefix = "bankRequestdata/bankRequestdata";

    @Autowired
    private IBankRequestdataService bankRequestdataService;

    @RequiresPermissions("bankRequestdata:bankRequestdata:view")
    @GetMapping()
    public String bankRequestdata()
    {
        return prefix + "/bankRequestdata";
    }

    /**
     * 查询请求渠道列表
     */
    @RequiresPermissions("bankRequestdata:bankRequestdata:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BankRequestdata bankRequestdata)throws Exception
    {
        startPage();
        List<BankRequestdata> list = bankRequestdataService.selectBankRequestdataList(bankRequestdata);
        for(int i=0;i<list.size();i++){
            list.get(i).setPan(Utils.dealCard(list.get(i).getPan()));
        }
        return getDataTable(list);
    }

    /**
     * 导出请求渠道列表
     */
    @RequiresPermissions("bankRequestdata:bankRequestdata:export")
    @Log(title = "请求渠道", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BankRequestdata bankRequestdata)
    {
        List<BankRequestdata> list = bankRequestdataService.selectBankRequestdataList(bankRequestdata);
        ExcelUtil<BankRequestdata> util = new ExcelUtil<BankRequestdata>(BankRequestdata.class);
        return util.exportExcel(list, "bankRequestdata");
    }

    /**
     * 新增请求渠道
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存请求渠道
     */
    @RequiresPermissions("bankRequestdata:bankRequestdata:add")
    @Log(title = "请求渠道", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BankRequestdata bankRequestdata)
    {
        return toAjax(bankRequestdataService.insertBankRequestdata(bankRequestdata));
    }

    /**
     * 修改请求渠道
     */
    @GetMapping("/edit/{serial}")
    public String edit(@PathVariable("serial") Long serial, ModelMap mmap)
    {
        BankRequestdata bankRequestdata = bankRequestdataService.selectBankRequestdataById(serial);
        mmap.put("bankRequestdata", bankRequestdata);
        return prefix + "/edit";
    }

    /**
     * 修改保存请求渠道
     */
    @RequiresPermissions("bankRequestdata:bankRequestdata:edit")
    @Log(title = "请求渠道", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BankRequestdata bankRequestdata)
    {
        return toAjax(bankRequestdataService.updateBankRequestdata(bankRequestdata));
    }

    /**
     * 删除请求渠道
     */
    @RequiresPermissions("bankRequestdata:bankRequestdata:remove")
    @Log(title = "请求渠道", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bankRequestdataService.deleteBankRequestdataByIds(ids));
    }
}
